home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Source Code
/
C
/
Frameworks
/
Grant's CGI Framework 1.0b12
/
Util
/
ErrorUtil.c
< prev
next >
Wrap
Text File
|
1995-12-09
|
4KB
|
177 lines
/*****
*
* ErrorUtil.c
*
* This is a support file for "Grant's CGI Framework".
* Please see the license agreement that accompanies the distribution package
* for licensing details.
*
* Copyright ©1995 by Grant Neufeld
* grant@acm.com
* http://arpp1.carleton.ca/grant/
*
*****/
#include "MyConfiguration.h"
#include <stdio.h>
#include <string.h>
#include "compiler_stuff.h"
#include "constants.h"
#include "globals.h"
#include "DebugUtil.h"
#include "ErrorInt.h"
#include "MemoryUtil.h"
#include "Quit.h"
#include "StringUtil.h"
#include "ErrorUtil.h"
/*** LOCAL CONSTANTS ***/
#define kstrErrorMissing "\pUnknown! Note the id number and contact the developer of this software."
/* the size of the above string + 1 for size byte */
#define kstrErrorMissingSize 72
/*** LOCAL PROTOTYPES ***/
static StringHandle errorSystemGetString ( OSErr, Str255 * );
static void errorSystemDisposeString ( StringHandle );
static void errorStartupGetString ( short, Str255 * );
/*** FUNCTIONS ***/
/* */
void
ErrorSystem ( OSErr errNum )
{
#if kCompileWithForeground && kCompileWithFullUserInterface
StringHandle errStrHdl; /* the human readable error string */
Str255 errNameStr; /* the name of the error */
errStrHdl = errorSystemGetString ( errNum, &errNameStr );
if ( (errStrHdl != nil) && (*errStrHdl != nil) )
{
/* errStrHdl was successfully retreived */
/* Display the alert. */
ErrorAlertSystemString ( errNum, errStrHdl, &errNameStr );
errorSystemDisposeString ( errStrHdl );
}
else
{
/* can't get system error string */
SysBeep ( 5 );
}
#endif
} /* ErrorSystem */
#pragma segment Startup
/* */
void
ErrorStartup ( short errNum )
{
#if kCompileWithForeground && kCompileWithFullUserInterface
Str255 errStr; /* the retrieved error string */
errorStartupGetString ( errNum, &errStr );
/* Display the alert. */
ErrorAlertStartupString ( (OSErr)errNum, &errStr );
#endif
ExitToShell ();
} /* ErrorStartup */
#pragma segment Main
/** String Retreival **/
/* return the system error's human readable string and it's constant name (errNameStr) */
static StringHandle
errorSystemGetString ( OSErr errNum, Str255 *errNameStr )
{
StringHandle errStrHdl; /* the retrieved error string */
StringHandle theString; /* the string to return */
short errID; /* just used for GetResInfo call */
ResType errType; /* just used for GetResInfo call */
/* Get message string for the error number. */
errStrHdl = (StringHandle) GetResource ( (ResType)krtErrStr, (short)errNum );
theString = nil;
if ( errStrHdl != nil )
{
theString = (StringHandle) MyNewHandle ( sizeof(Str255), nil );
}
if ( theString == nil )
{
/* if string isn't available, use generic error string */
theString = gSystemErrorStr;
(*errNameStr)[0] = nil;
}
else
{
HLock ( (Handle)errStrHdl );
HLock ( (Handle)theString );
StringPascalCopy ( (char *)(*errStrHdl), (char *)(*theString) );
HUnlock ( (Handle)errStrHdl );
HUnlock ( (Handle)theString );
ReleaseResource ( (Handle)errStrHdl );
/* get the error name from the resource */
GetResInfo ( (Handle)errStrHdl, &errID, &errType, *errNameStr );
}
return theString;
} /* errorSystemGetString */
/* dispose of the error string handle - don't do anything if it is the default string */
static void
errorSystemDisposeString ( StringHandle theString )
{
my_assert ( theString != nil, "\perrorSystemDisposeString: theString is nil" );
if ( theString != gSystemErrorStr )
{
DisposeHandle ( (Handle)theString );
}
} /* errorSystemDisposeString */
#pragma segment Startup
/* */
static void
errorStartupGetString ( short errNum, Str255 *errStr )
{
/* Get message string for the error number. */
GetIndString ( *errStr, krStartupErrorStrs, errNum );
if ( *errStr == nil )
{
/* if string isn't available, use generic error string */
StringPascalCopy ( (char *)kstrErrorMissing, (char *)(*errStr) );
}
} /* errorStartupGetString */
#pragma segment Main
/***** EOF *****/